<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>数组将维</title>
  </head>
  <body>
    <script>
      let arr = [1, 2, [3, 4, [5, 6], [7, 8, [9, 10]]]]
      function dimension(arr, n, result = []) {
        for (const value of arr) {
          if (n > 0 && Array.isArray(value)) {
            if (n > 1) {
              dimension(value, n - 1, result)
            } else {
              result.push(...value)
            }
          } else {
            result.push(value)
          }
        }
        return result
      }
      let arr2 = dimension(arr, 3)
    </script>
  </body>
</html>
